package math;

import io.GPSPoint;

import java.util.ArrayList;
import java.util.List;

import ui.TimeSeriesName;
import ui.TimeSeriesName.TimeSeriesType;

public class CalculatedPaceProvider extends AbstractStatsProvider {

	@Override
	public TimeSeriesName getName(String name) {
		return new TimeSeriesName(TimeSeriesType.SPEED, name, "Calculated Pace");
	}

	@Override
	void doWork() {
		List<Double> speed = new ArrayList<Double>();
		List<Long> timesL = new ArrayList<Long>();
		GPSPoint lastPoint = gpsTracks.get(0);
		for (int i = 1; i < gpsTracks.size(); i++) {
			GPSPoint currentPoint = gpsTracks.get(i);
			double sec = (currentPoint.getTime() - lastPoint.getTime()) / 1000.0;
			double cdist = Distance.distMeter(currentPoint, lastPoint);
			double v = cdist / sec;
			double p = sec * 1000.0 / (60 * cdist);
			speed.add(p);
			timesL.add(currentPoint.getTime());
			lastPoint = currentPoint;
		}
		values = Utils.toDoubles(speed);
		times = Utils.toLongs(timesL);
	}


}
